function onActionServerSide(action,member){
  if (action=="add"){
    if (player.clientr.leader!=player.account){
      player.chat="You are not the leader of this party!";
      return;
    }
    for (temp.pl : allplayers) {
      if (pl.account==member || pl.nick==member) {
        pl.clientr.sentacct=player.account;
        pl.clientr.sentnick=player.nick;
        pl.triggerClient("gui", name, "invite");
        player.chat="An invite has been sent";
      }
    }
  }
  if (action=="accept"){
    for (temp.pl : allplayers) {
      if (pl.account==player.clientr.sentacct){
        player.guild=pl.guild;
        pl.chat=player.nick@" has joined the party!";
        player.clientr.leader=pl.account;
        player.clientr.party=pl.guild;
        
        player.triggerClient("gui", name, "ps",member,player.nick);
      }
    }
  }
  if (action=="create"){
    for(temp.pl : allplayers){
      if (pl.guild==member){
        if (player.guild!=member){
          player.chat="This party name is currently taken";
          return;
        }
      }
    }
    player.guild=member;
    player.clientr.party=player.guild;
    player.clientr.leader=player.account;
    player.triggerClient("gui", name, "ps",member,player.nick);
  }
  if (action=="leave"){
    if (player.clientr.leader==player.account){
      for(temp.pl : allplayers){
        if (pl.clientr.leader==player.account){
          pl.clientr.leader="";
          pl.guild="";
          pl.clientr.party="";
          pl.chat="You've been kicked from the party";
          pl.triggerClient("gui", name, "leave",member,player.nick);
        }
      }
    }
    player.guild="";
    player.clientr.leader="";
    player.clientr.party="";
    player.triggerClient("gui", name, "leave",member,player.nick);
  }
  if (action=="kick"){
    if (player.clientr.leader==player.account){
      for(temp.pl : allplayers){
        if (pl.account==member || pl.nick==member){
          pl.guild="";
          pl.leader="";
          pl.clientr.party="";
          player.chat=pl.nick@" has been kicked from the party";
          pl.chat="You have been kicked from the party";
          pl.triggerClient("gui", name, "leave",member,player.nick);
          break;
        }
      }
    }else{
      player.chat="You are not the party leader";
    }
  }
  if (action=="name"){
    if (player.guild!="" || player.clientr.party!=""){
      player.guild=player.clientr.party;
    }
  }
  if (action=="chat"){
    for(temp.pl : allplayers){
      if (pl.clientr.leader==player.clientr.leader && pl.guild==player.guild){
        //pl.chat=player.nick@" : "@member;
        pl.triggerClient("gui", name, "chat",member,player.nick);
      }
    }
  }
}


function onPlayerLogout(p){
  for(temp.pl : allplayers){
    if (pl.clientr.leader==p.account){
      pl.guild="";
      pl.clientr.leader="";
      pl.clientr.party="";
      pl.triggerClient("gui", name, "leave",member,player.nick);
    }
  }
}


//#CLIENTSIDE
function onCreated(){
  this.mess= {"","","","",""};
  this.nicks={"","","","",""}; 
}
function onPlayerChats(){
  if (player.chat.starts("/invite")){
    temp.c=player.chat.substring(7).trim();
    triggerserver("gui", this.name, "add", temp.c, this.account);
  } 
  if (player.chat.starts("/create")){
    if (player.guild==""){
      temp.c=player.chat.substring(7).trim(); 
      triggerserver("gui", this.name, "create", temp.c, this.account);
    }else{
      player.chat="You are currentally in a party!";
    }
  }
  if (player.chat=="/leaveparty"){      
    triggerserver("gui", this.name, "leave", this.account);
  }
  if (player.chat.starts("/p")){
    if (player.guild!=""){
      temp.c=player.chat.substring(2).trim();
      player.chat=""; 
      triggerserver("gui", this.name, "chat", temp.c, this.account);
    }
  }
  if (player.chat.starts("/kick")){
    temp.c=player.chat.substring(5).trim();
    triggerserver("gui", this.name, "kick", temp.c, this.account);
  }
  if (player.chat.starts("setnick")){
    triggerserver("gui", this.name, "name",temp.c, this.account);
  }
}




function onActionClientside(action2,chat,n) { 
 if (action2=="invite"){
   new GuiWindowCtrl("Invite"){
     profile=GuiBlueWindowProfile;
     x=100;
     y=100;
     width=400;
     height=80;
     title=destroyOnHide=true;
     canMaximize=canResize=canMinimize=canClose=false;
  
     text = "Party Invite from "@clientr.sentacct@", "@clientr.sentnick;    
    
     new GuiButtonCtrl("Invite_Button"){
       profile=GuiBlueButtonProfile;
       x=30;
       y=30;
       width=100;
       height=30;
       text="Accept!";
     } 
     new GuiButtonCtrl("Ignore_Button"){
       profile=GuiBlueButtonProfile;
       x=150;
       y=30;
       width=100;
       height=30;
       text="Ignore";
     } 
     function Ignore_Button.onAction() {
       Ignore_Button.destroy();
       Invite_Button.destroy();
       Invite.destroy();
     } 
     function Invite_Button.onAction(){
       triggerserver("gui", this.name, "accept", temp.c, this.account);
       Ignore_Button.destroy();
       Invite_Button.destroy();
       Invite.destroy();
     }
   }
  }
  if (action2=="ps"){
    showText(999, 50, screenheight-225,"Times New Roman Baltic",NULL, "Party Chat:").layer=4;
    showText(998, 50, screenheight-250,"Times New Roman Baltic",NULL, "Party Leader: "@findplayer(clientr.leader).nick).layer=4;
    for(temp.a=0;temp.a<2;temp.a++){
      with(findimg(998+a)){
        zoom=0.9;
        textshadow=true;   
        alpha=1;
      }
    }
    this.mess= {"","","","",""};
    this.nicks={"","","","",""};
  }
  if (action2=="chat"){
    for(temp.a=6;temp.a>0;temp.a--){
      this.mess[a]=this.mess[a-1];
      this.nicks[a]=this.nicks[a-1];
    }
    this.mess[0]=chat;
    this.nicks[0]=n;
    for(temp.a=0;temp.a<=4;temp.a++){
      showText(1000+a, 50, screenheight-100-(20*a),"Times New Roman Baltic",NULL, this.nicks[a]@" : "@this.mess[a]).layer=4;
      with(findimg(1000+a)){
        zoom=0.8;
        textshadow=true;
        alpha=1;
      }
    }
    showText(999, 50, screenheight-225,"Times New Roman Baltic",NULL, "Party Chat:").layer=4;
    showText(998, 50, screenheight-250,"Times New Roman Baltic",NULL, "Party Leader: "@findplayer(clientr.leader).nick).layer=4;
    for(temp.a=0;temp.a<2;temp.a++){
      with(findimg(998+a)){
        zoom=0.9;
        textshadow=true;   
        alpha=1;
      }
    }
  }
  if (action2=="leave"){
    for(temp.a=0;temp.a<=8;temp.a++){
      //showText(998+a, 50, screenheight-250,$pref::graal::defaultfontname,NULL, "").layer=4;
      showText(998+a, 50, screenheight-250,"",NULL, "").layer=4;
    }
    this.mess= {"","","","",""};
    this.nicks={"","","","",""};
  }
  temp.tt=1;
  sleep(10);
  onTimeout(tt);
}
function onTimeout(tt){
    for(temp.a=0;temp.a<=8;temp.a++){
      with(findimg(998+a)){
        alpha=tt;
      }
    }
    tt=tt-0.02;
  if (tt>=0){
    sleep(0.05);
    onTimeout(tt);
  }
}
